package C042;

/**
 * ClassName: C02
 * Package: C042
 * Description: 牛吃草问题
 *
 * @Author BCXJ
 * @Create 2025/2/2 21:50
 * @Version 1.0
 * @Since 1.0
 */
public class C02 {
    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
            if(!process(i, "A").equals(process(i))) {
                System.out.println("error");
                return;
            }
            System.out.println(i+": " + process(i, "A"));
        }
    }


    public static String process(int rest, String cur) {
        String enemy = "A".equals(cur) ? "B" : "A";
        if(rest == 0) {
            return enemy;
        }
        for (int i = 1; i <= rest; i*=4) {
            String winner = process(rest - i, enemy);
            if(winner.equals(cur)) {
                return cur;
            }
        }
        return enemy;
    }

    public static String process(int rest) {
        int res = rest % 5;
        if(res == 0 || res == 2) {
            return "B";
        } else {
            return "A";
        }
    }
}
